home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / test / wtest.c < prev   
Encoding:
C/C++ Source or Header  |  1998-09-29  |  4.6 KB  |  173 lines

  1. /* quick and dirty test application that demonstrates: application hiding,
  2.  *    application defined titlebar button images, application defined
  3.  *    titlebar button actions, application menus, docking and
  4.  *    window manager commands 
  5.  * 
  6.  * Note that the windows don't have a window command menu.
  7.  *
  8.  * TODO: remake
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <X11/Xlib.h>
  13. #include <X11/Xutil.h>
  14. #include <X11/Xproto.h>
  15. #include <WMaker.h>
  16.  
  17. static unsigned char bits[] = {
  18.    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  19.    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  20.  
  21. static unsigned char mbits[] = {
  22.    0xff, 0x03, 0xff, 0x01, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00,
  23.    0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00};
  24.  
  25.  
  26. Display *dpy;
  27. Window leader;
  28. WMAppContext *app;
  29.  
  30.  
  31. static void 
  32. callback(void *foo, int item, Time time)
  33. {
  34.     printf("pushed item %i\n", item);
  35. }
  36.  
  37. static void
  38. quit(void *foo, int item, Time time)
  39. {
  40.     exit(0);
  41. }
  42.  
  43.  
  44.  
  45. static void
  46. hide(void *foo, int item, Time time)
  47. {
  48.     WMHideApplication(app);
  49. }
  50.  
  51.  
  52. Atom delete_win, miniaturize_win;
  53. Atom prots[6];
  54. GNUstepWMAttributes attr;
  55. XWMHints *hints;
  56. WMMenu *menu;
  57. WMMenu *submenu;
  58. int wincount=0;
  59.  
  60. static void 
  61. newwin(void *foo, int item, Time time)
  62. {
  63.     Window win;
  64.     XClassHint classhint;
  65.     char title[100];
  66.  
  67.     wincount++;
  68.     win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 
  69.                   10*wincount, 10*wincount, 200, 100, 0, 0, 0);
  70.     prots[0] = delete_win;
  71.     prots[1] = miniaturize_win;
  72.     XSetWMProtocols(dpy, win, prots, 2);
  73.     sprintf(title, "Test Window %i", wincount);
  74.     XStoreName(dpy, win, title);
  75.     
  76.     /* set class hint */
  77.     classhint.res_name = "test";
  78.     classhint.res_class = "Test";
  79.     XSetClassHint(dpy, win, &classhint);
  80.  
  81.     /* set WindowMaker hints */
  82.     attr.flags = GSMiniaturizePixmapAttr|GSMiniaturizeMaskAttr;
  83.     attr.miniaturize_pixmap = 
  84.       XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, 10, 10);
  85.     
  86.     attr.miniaturize_mask =
  87.       XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), mbits, 10, 10);
  88.  /*   
  89.     attr.flags |= GSWindowStyleAttr;
  90.     attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
  91. */
  92.     
  93.     WMSetWindowAttributes(dpy, win, &attr);
  94.  
  95.     hints = XAllocWMHints();
  96.     /* set window group leader */
  97.     hints->window_group = leader;
  98.     hints->flags = WindowGroupHint;
  99.     XSetWMHints(dpy, win, hints);
  100.  
  101.     WMAppAddWindow(app, win);   
  102.     XMapWindow(dpy, win);
  103. }
  104.  
  105. int main(int argc, char **argv)
  106. {    
  107.     XClassHint classhint;
  108.  
  109.     dpy = XOpenDisplay("");
  110.     if (!dpy) {
  111.     puts("could not open display!");
  112.     exit(1);
  113.     }
  114.     delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  115.     miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW", 
  116.                   False);
  117.  
  118.     leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10,
  119.                   0, 0, 0);
  120.     /* set class hint */
  121.     classhint.res_name = "test";
  122.     classhint.res_class = "Test";
  123.     XSetClassHint(dpy, leader, &classhint);
  124.  
  125.     /* set window group leader to self */
  126.     hints = XAllocWMHints();
  127.     hints->window_group = leader;
  128.     hints->flags = WindowGroupHint;
  129.     XSetWMHints(dpy, leader, hints);
  130.  
  131.     /* create app context */
  132.     app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
  133.     menu = WMMenuCreate(app, "Test Menu");
  134.     submenu = WMMenuCreate(app, "File");
  135.     WMMenuAddSubmenu(menu, "File", submenu);
  136.     
  137.     WMMenuAddItem(menu, "Hide", (WMMenuAction)hide, NULL, NULL, NULL);
  138.     WMMenuAddItem(menu, "Quit", (WMMenuAction)quit, NULL, NULL, NULL);
  139.     WMMenuAddItem(submenu, "New", (WMMenuAction)newwin, NULL, NULL, NULL);
  140.     WMMenuAddItem(submenu, "Open", (WMMenuAction)callback, NULL, NULL, NULL);
  141.     WMMenuAddItem(submenu, "Save", (WMMenuAction)callback, NULL, NULL, NULL);
  142.     WMMenuAddItem(submenu, "Save As...", (WMMenuAction)callback, NULL, NULL, NULL);
  143.     
  144.     WMAppSetMainMenu(app, menu);
  145.     
  146.     WMRealizeMenus(app);
  147.  
  148.     /* set command to use to startup this */
  149.     XSetCommand(dpy, leader, argv, argc);
  150.     
  151.     /* create first window */
  152.     newwin(NULL, 0, 0);
  153.  
  154.  
  155.     XFlush(dpy);
  156.     puts("Run xprop on the test window to see the properties defined");
  157.     while (wincount>0) {
  158.     XEvent ev;
  159.     XNextEvent(dpy, &ev);
  160.     if (ev.type==ClientMessage) {
  161.         if (ev.xclient.data.l[0]==delete_win) {
  162.         XDestroyWindow(dpy,ev.xclient.window);
  163.         wincount--;
  164.         } else if (ev.xclient.data.l[0]==miniaturize_win) {
  165.         puts("You've pushed the maximize window button");
  166.         }
  167.     } 
  168.     WMProcessEvent(app, &ev);
  169.     }
  170.     exit(0);
  171. }
  172.  
  173.